/*
 * Copyright (c) 2007-2020 西安交通信息投资营运有限公司 版权所有
 */

package com.xci.edu.core.api;

import com.github.lvyanyang.annotation.Authorize;
import com.github.lvyanyang.core.BaseController;
import com.github.lvyanyang.core.BoolResult;
import com.github.lvyanyang.core.Const;
import com.github.lvyanyang.core.PageList;
import com.github.lvyanyang.core.XCI;
import com.xci.edu.core.entity.EduCourseware;
import com.xci.edu.core.filter.EduCoursewareFilter;
import com.xci.edu.core.service.EduCoursewareService;
import com.github.lvyanyang.model.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 课程信息接口
 * @author 焦元义 jiaoyuanyi@xci96716.com
 * @since 2020-11-24 15:14:37
 */
@Api(tags = "课程信息接口")
@Authorize
@RestController
@RequestMapping(value = "/api/core/eduCourseware", produces = Const.PROJSON)
public class EduCoursewareApiController extends BaseController {
    /** 课程信息服务 */
    @Resource private EduCoursewareService eduCoursewareService;

    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "新建课程信息")
    //@Authorize(code = "core.eduCourseware.insert")
    @PostMapping("/insert")
    public BoolResult insert(@RequestBody EduCourseware entity) {
        return eduCoursewareService.insert(entity);
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "修改课程信息")
    //@Authorize(code = "core.eduCourseware.update")
    @PostMapping("/update")
    public BoolResult update(@RequestBody EduCourseware entity) {
        return eduCoursewareService.update(entity);
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "修改课程信息状态")
    //@Authorize(code = "core.eduCourseware.updateStatus")
    @PostMapping(value = "/updateStatus")
    public BoolResult updateStatus(@RequestBody IdsStatusBody body) {
        eduCoursewareService.updateStatus(body.getIds(), body.getStatus());
        return BoolResult.success();
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "根据主键字符串删除课程信息")
    //@Authorize(code = "core.eduCourseware.delete")
    @PostMapping(value = "/delete")
    public BoolResult delete(@RequestBody IdsBody body) {
        return eduCoursewareService.delete(body.getIds());
    }

    //@ApiOperationSupport(order = 5)
    //@ApiOperation(value = "检查课程信息名称是否存在")
    //@PostMapping(value = "/existByName")
    //public BoolResult existByName(@RequestBody NameExcludeIdBody body) {
    //    return BoolResult.success(eduCoursewareService.existByName(body.getName(), body.getExcludeId()));
    //}

    @ApiOperationSupport(order = 7)
    @ApiOperation(value = "根据主键查询单个课程信息")
    //@Authorize(code = "core.eduCourseware.select")
    @PostMapping("/selectById")
    public BoolResult<EduCourseware> selectById(@RequestBody IdBody body) {
        return BoolResult.success(eduCoursewareService.selectById(body.getId()));
    }

    @ApiOperationSupport(order = 9)
    @ApiOperation(value = "查询课程信息分页列表")
    //@Authorize(code = "core.eduCourseware.select")
    @PostMapping("/selectPageList")
    public BoolResult<PageList<EduCourseware>> selectPageList(@RequestBody EduCoursewareFilter filter) {
        return BoolResult.success(eduCoursewareService.selectPageList(filter));
    }

    @ApiOperationSupport(order = 10, ignoreParameters = {Const.IPI, Const.IPS, Const.IPSN, Const.IPSD})
    @ApiOperation(value = "查询课程信息列表")
    //@Authorize(code = "core.eduCourseware.select")
    @PostMapping("/selectList")
    public BoolResult<List<EduCourseware>> selectList(@RequestBody EduCoursewareFilter filter) {
        return BoolResult.success(eduCoursewareService.selectList(filter));
    }

    @ApiOperationSupport(order = 11, ignoreParameters = {Const.IPI, Const.IPS, Const.IPSN, Const.IPSD})
    @ApiOperation(value = "导出课程信息列表")
    //@Authorize(code = "core.eduCourseware.export")
    @PostMapping(value = "/export", produces = {Const.PROOCTET, Const.PROJSON})
    public void export(@RequestBody EduCoursewareFilter filter) {
        XCI.exportExcel(eduCoursewareService.selectList(filter), EduCourseware.class, "课程信息列表");
    }

    //@ApiOperationSupport(order = 12)
    //@ApiOperation(value = "获取课程信息导出字段")
    //@PostMapping(value = "/exportNames")
    //public BoolResult<List<String>> exportNames() {
    //    return BoolResult.success(XCI.getExcelFiledNames(EduCourseware.class));
    //}
}
